﻿#region Using directives

using System;
using System.Data;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;

using NetROS.Tiers.Entities;
using NetROS.Tiers.Data;

#endregion

namespace NetROS.Tiers.Data.Bases
{	
	///<summary>
	/// This class is the base class for any <see cref="DjelatnikProviderBase"/> implementation.
	/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
	///</summary>
	public abstract partial class DjelatnikProviderBaseCore : EntityProviderBase<NetROS.Tiers.Entities.Djelatnik, NetROS.Tiers.Entities.DjelatnikKey>
	{		
		#region Get from Many To Many Relationship Functions
		#region GetByIDGrupaDjelatnikFromDjelatnikInGrupa
		
		/// <summary>
		///		Gets tblDjelatnik objects from the datasource by IDGrupaDjelatnik in the
		///		tblDjelatnikInGrupa table. Table tblDjelatnik is related to table tblGrupaDjelatnik
		///		through the (M:N) relationship defined in the tblDjelatnikInGrupa table.
		/// </summary>
		/// <param name="iDGrupaDjelatnik"></param>
		/// <returns>Returns a typed collection of Djelatnik objects.</returns>
		public TList<Djelatnik> GetByIDGrupaDjelatnikFromDjelatnikInGrupa(System.Int32 iDGrupaDjelatnik)
		{
			int count = -1;
			return GetByIDGrupaDjelatnikFromDjelatnikInGrupa(null,iDGrupaDjelatnik, 0, int.MaxValue, out count);
			
		}
		
		/// <summary>
		///		Gets NetROS.Tiers.Entities.Djelatnik objects from the datasource by IDGrupaDjelatnik in the
		///		tblDjelatnikInGrupa table. Table tblDjelatnik is related to table tblGrupaDjelatnik
		///		through the (M:N) relationship defined in the tblDjelatnikInGrupa table.
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="iDGrupaDjelatnik"></param>
		/// <remarks></remarks>
		/// <returns>Returns a TList of Djelatnik objects.</returns>
		public TList<Djelatnik> GetByIDGrupaDjelatnikFromDjelatnikInGrupa(System.Int32 iDGrupaDjelatnik, int start, int pageLength)
		{
			int count = -1;
			return GetByIDGrupaDjelatnikFromDjelatnikInGrupa(null, iDGrupaDjelatnik, start, pageLength, out count);
		}
		
		/// <summary>
		///		Gets Djelatnik objects from the datasource by IDGrupaDjelatnik in the
		///		tblDjelatnikInGrupa table. Table tblDjelatnik is related to table tblGrupaDjelatnik
		///		through the (M:N) relationship defined in the tblDjelatnikInGrupa table.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="iDGrupaDjelatnik"></param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of tblDjelatnik objects.</returns>
		public TList<Djelatnik> GetByIDGrupaDjelatnikFromDjelatnikInGrupa(TransactionManager transactionManager, System.Int32 iDGrupaDjelatnik)
		{
			int count = -1;
			return GetByIDGrupaDjelatnikFromDjelatnikInGrupa(transactionManager, iDGrupaDjelatnik, 0, int.MaxValue, out count);
		}
		
		
		/// <summary>
		///		Gets Djelatnik objects from the datasource by IDGrupaDjelatnik in the
		///		tblDjelatnikInGrupa table. Table tblDjelatnik is related to table tblGrupaDjelatnik
		///		through the (M:N) relationship defined in the tblDjelatnikInGrupa table.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="iDGrupaDjelatnik"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of tblDjelatnik objects.</returns>
		public TList<Djelatnik> GetByIDGrupaDjelatnikFromDjelatnikInGrupa(TransactionManager transactionManager, System.Int32 iDGrupaDjelatnik,int start, int pageLength)
		{
			int count = -1;
			return GetByIDGrupaDjelatnikFromDjelatnikInGrupa(transactionManager, iDGrupaDjelatnik, start, pageLength, out count);
		}
		
		/// <summary>
		///		Gets Djelatnik objects from the datasource by IDGrupaDjelatnik in the
		///		tblDjelatnikInGrupa table. Table tblDjelatnik is related to table tblGrupaDjelatnik
		///		through the (M:N) relationship defined in the tblDjelatnikInGrupa table.
		/// </summary>
		/// <param name="iDGrupaDjelatnik"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of tblDjelatnik objects.</returns>
		public TList<Djelatnik> GetByIDGrupaDjelatnikFromDjelatnikInGrupa(System.Int32 iDGrupaDjelatnik,int start, int pageLength, out int count)
		{
			
			return GetByIDGrupaDjelatnikFromDjelatnikInGrupa(null, iDGrupaDjelatnik, start, pageLength, out count);
		}


		/// <summary>
		///		Gets tblDjelatnik objects from the datasource by IDGrupaDjelatnik in the
		///		tblDjelatnikInGrupa table. Table tblDjelatnik is related to table tblGrupaDjelatnik
		///		through the (M:N) relationship defined in the tblDjelatnikInGrupa table.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <param name="iDGrupaDjelatnik"></param>
		/// <remarks></remarks>
		/// <returns>Returns a TList of Djelatnik objects.</returns>
		public abstract TList<Djelatnik> GetByIDGrupaDjelatnikFromDjelatnikInGrupa(TransactionManager transactionManager,System.Int32 iDGrupaDjelatnik, int start, int pageLength, out int count);
		
		#endregion GetByIDGrupaDjelatnikFromDjelatnikInGrupa
		
		#endregion	
		
		#region Delete Methods

		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="transactionManager">A <see cref="TransactionManager"/> object.</param>
		/// <param name="key">The unique identifier of the row to delete.</param>
		/// <returns>Returns true if operation suceeded.</returns>
		public override bool Delete(TransactionManager transactionManager, NetROS.Tiers.Entities.DjelatnikKey key)
		{
			return Delete(transactionManager, key.ID);
		}
		
		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="iD">. Primary Key.</param>
		/// <remarks>Deletes based on primary key(s).</remarks>
		/// <returns>Returns true if operation suceeded.</returns>
		public bool Delete(System.Int32 iD)
		{
			return Delete(null, iD);
		}
		
		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="iD">. Primary Key.</param>
		/// <remarks>Deletes based on primary key(s).</remarks>
		/// <returns>Returns true if operation suceeded.</returns>
		public abstract bool Delete(TransactionManager transactionManager, System.Int32 iD);		
		
		#endregion Delete Methods
		
		#region Get By Foreign Key Functions
	
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_tblDjelatnik_tblOrganizacija key.
		///		FK_tblDjelatnik_tblOrganizacija Description: 
		/// </summary>
		/// <param name="iDOrganizacija"></param>
		/// <returns>Returns a typed collection of NetROS.Tiers.Entities.Djelatnik objects.</returns>
		public NetROS.Tiers.Entities.TList<Djelatnik> GetByIDOrganizacija(System.Int32 iDOrganizacija)
		{
			int count = -1;
			return GetByIDOrganizacija(iDOrganizacija, 0,int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_tblDjelatnik_tblOrganizacija key.
		///		FK_tblDjelatnik_tblOrganizacija Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="iDOrganizacija"></param>
		/// <returns>Returns a typed collection of NetROS.Tiers.Entities.Djelatnik objects.</returns>
		/// <remarks></remarks>
		public NetROS.Tiers.Entities.TList<Djelatnik> GetByIDOrganizacija(TransactionManager transactionManager, System.Int32 iDOrganizacija)
		{
			int count = -1;
			return GetByIDOrganizacija(transactionManager, iDOrganizacija, 0, int.MaxValue, out count);
		}
		
			/// <summary>
		/// 	Gets rows from the datasource based on the FK_tblDjelatnik_tblOrganizacija key.
		///		FK_tblDjelatnik_tblOrganizacija Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="iDOrganizacija"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of NetROS.Tiers.Entities.Djelatnik objects.</returns>
		public NetROS.Tiers.Entities.TList<Djelatnik> GetByIDOrganizacija(TransactionManager transactionManager, System.Int32 iDOrganizacija, int start, int pageLength)
		{
			int count = -1;
			return GetByIDOrganizacija(transactionManager, iDOrganizacija, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_tblDjelatnik_tblOrganizacija key.
		///		fK_tblDjelatnik_tblOrganizacija Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="iDOrganizacija"></param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of NetROS.Tiers.Entities.Djelatnik objects.</returns>
		public NetROS.Tiers.Entities.TList<Djelatnik> GetByIDOrganizacija(System.Int32 iDOrganizacija, int start, int pageLength)
		{
			int count =  -1;
			return GetByIDOrganizacija(null, iDOrganizacija, start, pageLength,out count);	
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_tblDjelatnik_tblOrganizacija key.
		///		fK_tblDjelatnik_tblOrganizacija Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="iDOrganizacija"></param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of NetROS.Tiers.Entities.Djelatnik objects.</returns>
		public NetROS.Tiers.Entities.TList<Djelatnik> GetByIDOrganizacija(System.Int32 iDOrganizacija, int start, int pageLength,out int count)
		{
			return GetByIDOrganizacija(null, iDOrganizacija, start, pageLength, out count);	
		}
						
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_tblDjelatnik_tblOrganizacija key.
		///		FK_tblDjelatnik_tblOrganizacija Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="iDOrganizacija"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns a typed collection of NetROS.Tiers.Entities.Djelatnik objects.</returns>
		public abstract NetROS.Tiers.Entities.TList<Djelatnik> GetByIDOrganizacija(TransactionManager transactionManager, System.Int32 iDOrganizacija, int start, int pageLength, out int count);
		
		#endregion

		#region Get By Index Functions
		
		/// <summary>
		/// 	Gets a row from the DataSource based on its primary key.
		/// </summary>
		/// <param name="transactionManager">A <see cref="TransactionManager"/> object.</param>
		/// <param name="key">The unique identifier of the row to retrieve.</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <returns>Returns an instance of the Entity class.</returns>
		public override NetROS.Tiers.Entities.Djelatnik Get(TransactionManager transactionManager, NetROS.Tiers.Entities.DjelatnikKey key, int start, int pageLength)
		{
			return GetByID(transactionManager, key.ID, start, pageLength);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the primary key IX_tblDjelatnikNaziv index.
		/// </summary>
		/// <param name="naziv"></param>
		/// <returns>Returns an instance of the <see cref="NetROS.Tiers.Entities.Djelatnik"/> class.</returns>
		public NetROS.Tiers.Entities.Djelatnik GetByNaziv(System.String naziv)
		{
			int count = -1;
			return GetByNaziv(null,naziv, 0, int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the IX_tblDjelatnikNaziv index.
		/// </summary>
		/// <param name="naziv"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="NetROS.Tiers.Entities.Djelatnik"/> class.</returns>
		public NetROS.Tiers.Entities.Djelatnik GetByNaziv(System.String naziv, int start, int pageLength)
		{
			int count = -1;
			return GetByNaziv(null, naziv, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the IX_tblDjelatnikNaziv index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="naziv"></param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="NetROS.Tiers.Entities.Djelatnik"/> class.</returns>
		public NetROS.Tiers.Entities.Djelatnik GetByNaziv(TransactionManager transactionManager, System.String naziv)
		{
			int count = -1;
			return GetByNaziv(transactionManager, naziv, 0, int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the IX_tblDjelatnikNaziv index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="naziv"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="NetROS.Tiers.Entities.Djelatnik"/> class.</returns>
		public NetROS.Tiers.Entities.Djelatnik GetByNaziv(TransactionManager transactionManager, System.String naziv, int start, int pageLength)
		{
			int count = -1;
			return GetByNaziv(transactionManager, naziv, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the IX_tblDjelatnikNaziv index.
		/// </summary>
		/// <param name="naziv"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="NetROS.Tiers.Entities.Djelatnik"/> class.</returns>
		public NetROS.Tiers.Entities.Djelatnik GetByNaziv(System.String naziv, int start, int pageLength, out int count)
		{
			return GetByNaziv(null, naziv, start, pageLength, out count);
		}
		
				
		/// <summary>
		/// 	Gets rows from the datasource based on the IX_tblDjelatnikNaziv index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="naziv"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns an instance of the <see cref="NetROS.Tiers.Entities.Djelatnik"/> class.</returns>
		public abstract NetROS.Tiers.Entities.Djelatnik GetByNaziv(TransactionManager transactionManager, System.String naziv, int start, int pageLength, out int count);
						
		/// <summary>
		/// 	Gets rows from the datasource based on the primary key PK_tblDjelatnik index.
		/// </summary>
		/// <param name="iD"></param>
		/// <returns>Returns an instance of the <see cref="NetROS.Tiers.Entities.Djelatnik"/> class.</returns>
		public NetROS.Tiers.Entities.Djelatnik GetByID(System.Int32 iD)
		{
			int count = -1;
			return GetByID(null,iD, 0, int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_tblDjelatnik index.
		/// </summary>
		/// <param name="iD"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="NetROS.Tiers.Entities.Djelatnik"/> class.</returns>
		public NetROS.Tiers.Entities.Djelatnik GetByID(System.Int32 iD, int start, int pageLength)
		{
			int count = -1;
			return GetByID(null, iD, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_tblDjelatnik index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="iD"></param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="NetROS.Tiers.Entities.Djelatnik"/> class.</returns>
		public NetROS.Tiers.Entities.Djelatnik GetByID(TransactionManager transactionManager, System.Int32 iD)
		{
			int count = -1;
			return GetByID(transactionManager, iD, 0, int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_tblDjelatnik index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="iD"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="NetROS.Tiers.Entities.Djelatnik"/> class.</returns>
		public NetROS.Tiers.Entities.Djelatnik GetByID(TransactionManager transactionManager, System.Int32 iD, int start, int pageLength)
		{
			int count = -1;
			return GetByID(transactionManager, iD, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_tblDjelatnik index.
		/// </summary>
		/// <param name="iD"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="NetROS.Tiers.Entities.Djelatnik"/> class.</returns>
		public NetROS.Tiers.Entities.Djelatnik GetByID(System.Int32 iD, int start, int pageLength, out int count)
		{
			return GetByID(null, iD, start, pageLength, out count);
		}
		
				
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_tblDjelatnik index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="iD"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns an instance of the <see cref="NetROS.Tiers.Entities.Djelatnik"/> class.</returns>
		public abstract NetROS.Tiers.Entities.Djelatnik GetByID(TransactionManager transactionManager, System.Int32 iD, int start, int pageLength, out int count);
						
		#endregion "Get By Index Functions"
	
		#region Custom Methods
		
		
		#endregion

		#region Helper Functions	
		
		/// <summary>
		/// Fill a NetROS.Tiers.Entities.TList&lt;Djelatnik&gt; From a DataReader.
		/// </summary>
		/// <param name="reader">Datareader</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">number of rows.</param>
		/// <returns>a <see cref="NetROS.Tiers.Entities.TList&lt;Djelatnik&gt;"/></returns>
		public static NetROS.Tiers.Entities.TList<Djelatnik> Fill(IDataReader reader, NetROS.Tiers.Entities.TList<Djelatnik> rows, int start, int pageLength)
		{
		// advance to the starting row
		for (int i = 0; i < start; i++)
		{
			if (!reader.Read())
			return rows; // not enough rows, just return
		}
		for (int i = 0; i < pageLength; i++)
		{
			if (!reader.Read())
			break; // we are done
			string key = null;
			
			NetROS.Tiers.Entities.Djelatnik c = null;
			if (DataRepository.Provider.UseEntityFactory)
			{
			key = new System.Text.StringBuilder("Djelatnik")
			.Append("|").Append((reader.IsDBNull(((int)NetROS.Tiers.Entities.DjelatnikColumn.ID - 1))?(int)0:(System.Int32)reader[((int)NetROS.Tiers.Entities.DjelatnikColumn.ID - 1)]).ToString()).ToString();
			c = EntityManager.LocateOrCreate<Djelatnik>(
			key.ToString(), // EntityTrackingKey
			"Djelatnik",  //Creational Type
			DataRepository.Provider.EntityCreationalFactoryType,  //Factory used to create entity
			DataRepository.Provider.EnableEntityTracking); // Track this entity?
			}
			else
			{
			c = new NetROS.Tiers.Entities.Djelatnik();
			}
			
			if (!DataRepository.Provider.EnableEntityTracking ||
			c.EntityState == EntityState.Added ||
			(DataRepository.Provider.EnableEntityTracking &&
			((DataRepository.Provider.CurrentLoadPolicy == LoadPolicy.PreserveChanges && c.EntityState == EntityState.Unchanged) ||
			(DataRepository.Provider.CurrentLoadPolicy == LoadPolicy.DiscardChanges && (c.EntityState == EntityState.Unchanged ||
								c.EntityState == EntityState.Changed)))))
						{
			c.SuppressEntityEvents = true;
			c.ID = (System.Int32)reader["ID"];
			c.Naziv = (System.String)reader["Naziv"];
			c.PrikaznoIme = (System.String)reader["PrikaznoIme"];
			c.IDOrganizacija = (System.Int32)reader["IDOrganizacija"];
			c.EntityTrackingKey = key;
			c.AcceptChanges();
			c.SuppressEntityEvents = false;
			}
			rows.Add(c);
		}
		return rows;
		}		
		/// <summary>
		/// Refreshes the <see cref="NetROS.Tiers.Entities.Djelatnik"/> object from the <see cref="IDataReader"/>.
		/// </summary>
		/// <param name="reader">The <see cref="IDataReader"/> to read from.</param>
		/// <param name="entity">The <see cref="NetROS.Tiers.Entities.Djelatnik"/> object to refresh.</param>
		public static void RefreshEntity(IDataReader reader, NetROS.Tiers.Entities.Djelatnik entity)
		{
			if (!reader.Read()) return;
			
			entity.ID = (System.Int32)reader["ID"];
			entity.Naziv = (System.String)reader["Naziv"];
			entity.PrikaznoIme = (System.String)reader["PrikaznoIme"];
			entity.IDOrganizacija = (System.Int32)reader["IDOrganizacija"];
			entity.AcceptChanges();
		}
		
		/// <summary>
		/// Refreshes the <see cref="NetROS.Tiers.Entities.Djelatnik"/> object from the <see cref="DataSet"/>.
		/// </summary>
		/// <param name="dataSet">The <see cref="DataSet"/> to read from.</param>
		/// <param name="entity">The <see cref="NetROS.Tiers.Entities.Djelatnik"/> object.</param>
		public static void RefreshEntity(DataSet dataSet, NetROS.Tiers.Entities.Djelatnik entity)
		{
			DataRow dataRow = dataSet.Tables[0].Rows[0];
			
			entity.ID = (System.Int32)dataRow["ID"];
			entity.Naziv = (System.String)dataRow["Naziv"];
			entity.PrikaznoIme = (System.String)dataRow["PrikaznoIme"];
			entity.IDOrganizacija = (System.Int32)dataRow["IDOrganizacija"];
			entity.AcceptChanges();
		}
		#endregion 
		
		#region DeepLoad Methods
		/// <summary>
		/// Deep Loads the <see cref="IEntity"/> object with criteria based of the child 
		/// property collections only N Levels Deep based on the <see cref="DeepLoadType"/>.
		/// </summary>
		/// <remarks>
		/// Use this method with caution as it is possible to DeepLoad with Recursion and traverse an entire object graph.
		/// </remarks>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="entity">The <see cref="NetROS.Tiers.Entities.Djelatnik"/> object to load.</param>
		/// <param name="deep">Boolean. A flag that indicates whether to recursively save all Property Collection that are descendants of this instance. If True, saves the complete object graph below this object. If False, saves this object only. </param>
		/// <param name="deepLoadType">DeepLoadType Enumeration to Include/Exclude object property collections from Load.</param>
		/// <param name="childTypes">NetROS.Tiers.Entities.Djelatnik Property Collection Type Array To Include or Exclude from Load</param>
		/// <param name="innerList">A collection of child types for easy access.</param>
	    /// <exception cref="ArgumentNullException">entity or childTypes is null.</exception>
	    /// <exception cref="ArgumentException">deepLoadType has invalid value.</exception>
		internal override void DeepLoad(TransactionManager transactionManager, NetROS.Tiers.Entities.Djelatnik entity, bool deep, DeepLoadType deepLoadType, System.Type[] childTypes, DeepSession innerList)
		{
			if(entity == null)
				return;

			#region IDOrganizacijaSource	
			if (CanDeepLoad(entity, "Organizacija|IDOrganizacijaSource", deepLoadType, innerList) 
				&& entity.IDOrganizacijaSource == null)
			{
				object[] pkItems = new object[1];
				pkItems[0] = entity.IDOrganizacija;
				Organizacija tmpEntity = EntityManager.LocateEntity<Organizacija>(EntityLocator.ConstructKeyFromPkItems(typeof(Organizacija), pkItems), DataRepository.Provider.EnableEntityTracking);
				if (tmpEntity != null)
					entity.IDOrganizacijaSource = tmpEntity;
				else
					entity.IDOrganizacijaSource = DataRepository.OrganizacijaProvider.GetByID(transactionManager, entity.IDOrganizacija);		
				
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'IDOrganizacijaSource' loaded. key " + entity.EntityTrackingKey);
				#endif 
				
				if (deep && entity.IDOrganizacijaSource != null)
				{
					innerList.SkipChildren = true;
					DataRepository.OrganizacijaProvider.DeepLoad(transactionManager, entity.IDOrganizacijaSource, deep, deepLoadType, childTypes, innerList);
					innerList.SkipChildren = false;
				}
					
			}
			#endregion IDOrganizacijaSource
			
			//used to hold DeepLoad method delegates and fire after all the local children have been loaded.
			Dictionary<string, KeyValuePair<Delegate, object>> deepHandles = new Dictionary<string, KeyValuePair<Delegate, object>>();
			// Deep load child collections  - Call GetByID methods when available
			
			#region DokumentStavkaCollection
			//Relationship Type One : Many
			if (CanDeepLoad(entity, "List<DokumentStavka>|DokumentStavkaCollection", deepLoadType, innerList)) 
			{
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'DokumentStavkaCollection' loaded. key " + entity.EntityTrackingKey);
				#endif 

				entity.DokumentStavkaCollection = DataRepository.DokumentStavkaProvider.GetByIDUserModified(transactionManager, entity.ID);

				if (deep && entity.DokumentStavkaCollection.Count > 0)
				{
					deepHandles.Add("DokumentStavkaCollection",
						new KeyValuePair<Delegate, object>((DeepLoadHandle<DokumentStavka>) DataRepository.DokumentStavkaProvider.DeepLoad,
						new object[] { transactionManager, entity.DokumentStavkaCollection, deep, deepLoadType, childTypes, innerList }
					));
				}
			}		
			#endregion 
			
			
			#region KnjizenjeCollectionGetByIDUserModified
			//Relationship Type One : Many
			if (CanDeepLoad(entity, "List<Knjizenje>|KnjizenjeCollectionGetByIDUserModified", deepLoadType, innerList)) 
			{
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'KnjizenjeCollectionGetByIDUserModified' loaded. key " + entity.EntityTrackingKey);
				#endif 

				entity.KnjizenjeCollectionGetByIDUserModified = DataRepository.KnjizenjeProvider.GetByIDUserModified(transactionManager, entity.ID);

				if (deep && entity.KnjizenjeCollectionGetByIDUserModified.Count > 0)
				{
					deepHandles.Add("KnjizenjeCollectionGetByIDUserModified",
						new KeyValuePair<Delegate, object>((DeepLoadHandle<Knjizenje>) DataRepository.KnjizenjeProvider.DeepLoad,
						new object[] { transactionManager, entity.KnjizenjeCollectionGetByIDUserModified, deep, deepLoadType, childTypes, innerList }
					));
				}
			}		
			#endregion 
			
			
			#region KnjizenjeStavkaCollectionGetByIDUserCreated
			//Relationship Type One : Many
			if (CanDeepLoad(entity, "List<KnjizenjeStavka>|KnjizenjeStavkaCollectionGetByIDUserCreated", deepLoadType, innerList)) 
			{
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'KnjizenjeStavkaCollectionGetByIDUserCreated' loaded. key " + entity.EntityTrackingKey);
				#endif 

				entity.KnjizenjeStavkaCollectionGetByIDUserCreated = DataRepository.KnjizenjeStavkaProvider.GetByIDUserCreated(transactionManager, entity.ID);

				if (deep && entity.KnjizenjeStavkaCollectionGetByIDUserCreated.Count > 0)
				{
					deepHandles.Add("KnjizenjeStavkaCollectionGetByIDUserCreated",
						new KeyValuePair<Delegate, object>((DeepLoadHandle<KnjizenjeStavka>) DataRepository.KnjizenjeStavkaProvider.DeepLoad,
						new object[] { transactionManager, entity.KnjizenjeStavkaCollectionGetByIDUserCreated, deep, deepLoadType, childTypes, innerList }
					));
				}
			}		
			#endregion 
			
			
			#region DokumentCollectionGetByIDUserPrimio
			//Relationship Type One : Many
			if (CanDeepLoad(entity, "List<Dokument>|DokumentCollectionGetByIDUserPrimio", deepLoadType, innerList)) 
			{
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'DokumentCollectionGetByIDUserPrimio' loaded. key " + entity.EntityTrackingKey);
				#endif 

				entity.DokumentCollectionGetByIDUserPrimio = DataRepository.DokumentProvider.GetByIDUserPrimio(transactionManager, entity.ID);

				if (deep && entity.DokumentCollectionGetByIDUserPrimio.Count > 0)
				{
					deepHandles.Add("DokumentCollectionGetByIDUserPrimio",
						new KeyValuePair<Delegate, object>((DeepLoadHandle<Dokument>) DataRepository.DokumentProvider.DeepLoad,
						new object[] { transactionManager, entity.DokumentCollectionGetByIDUserPrimio, deep, deepLoadType, childTypes, innerList }
					));
				}
			}		
			#endregion 
			
			
			#region GrupaDjelatnikCollection_From_DjelatnikInGrupa
			// RelationshipType.ManyToMany
			if (CanDeepLoad(entity, "List<GrupaDjelatnik>|GrupaDjelatnikCollection_From_DjelatnikInGrupa", deepLoadType, innerList))
			{
				entity.GrupaDjelatnikCollection_From_DjelatnikInGrupa = DataRepository.GrupaDjelatnikProvider.GetByIDDjelatnikFromDjelatnikInGrupa(transactionManager, entity.ID);			 
		
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'GrupaDjelatnikCollection_From_DjelatnikInGrupa' loaded. key " + entity.EntityTrackingKey);
				#endif 
				
				if (deep && entity.GrupaDjelatnikCollection_From_DjelatnikInGrupa != null)
				{
					deepHandles.Add("GrupaDjelatnikCollection_From_DjelatnikInGrupa",
						new KeyValuePair<Delegate, object>((DeepLoadHandle< GrupaDjelatnik >) DataRepository.GrupaDjelatnikProvider.DeepLoad,
						new object[] { transactionManager, entity.GrupaDjelatnikCollection_From_DjelatnikInGrupa, deep, deepLoadType, childTypes, innerList }
					));
				}
			}
			#endregion
			
			
			
			#region ObracunKamataCollection
			//Relationship Type One : Many
			if (CanDeepLoad(entity, "List<ObracunKamata>|ObracunKamataCollection", deepLoadType, innerList)) 
			{
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'ObracunKamataCollection' loaded. key " + entity.EntityTrackingKey);
				#endif 

				entity.ObracunKamataCollection = DataRepository.ObracunKamataProvider.GetByIDUserModified(transactionManager, entity.ID);

				if (deep && entity.ObracunKamataCollection.Count > 0)
				{
					deepHandles.Add("ObracunKamataCollection",
						new KeyValuePair<Delegate, object>((DeepLoadHandle<ObracunKamata>) DataRepository.ObracunKamataProvider.DeepLoad,
						new object[] { transactionManager, entity.ObracunKamataCollection, deep, deepLoadType, childTypes, innerList }
					));
				}
			}		
			#endregion 
			
			
			#region KnjizenjeStavkaCollectionGetByIDUserModified
			//Relationship Type One : Many
			if (CanDeepLoad(entity, "List<KnjizenjeStavka>|KnjizenjeStavkaCollectionGetByIDUserModified", deepLoadType, innerList)) 
			{
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'KnjizenjeStavkaCollectionGetByIDUserModified' loaded. key " + entity.EntityTrackingKey);
				#endif 

				entity.KnjizenjeStavkaCollectionGetByIDUserModified = DataRepository.KnjizenjeStavkaProvider.GetByIDUserModified(transactionManager, entity.ID);

				if (deep && entity.KnjizenjeStavkaCollectionGetByIDUserModified.Count > 0)
				{
					deepHandles.Add("KnjizenjeStavkaCollectionGetByIDUserModified",
						new KeyValuePair<Delegate, object>((DeepLoadHandle<KnjizenjeStavka>) DataRepository.KnjizenjeStavkaProvider.DeepLoad,
						new object[] { transactionManager, entity.KnjizenjeStavkaCollectionGetByIDUserModified, deep, deepLoadType, childTypes, innerList }
					));
				}
			}		
			#endregion 
			
			
			#region KlijentNapomenaCollectionGetByIDUserModified
			//Relationship Type One : Many
			if (CanDeepLoad(entity, "List<KlijentNapomena>|KlijentNapomenaCollectionGetByIDUserModified", deepLoadType, innerList)) 
			{
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'KlijentNapomenaCollectionGetByIDUserModified' loaded. key " + entity.EntityTrackingKey);
				#endif 

				entity.KlijentNapomenaCollectionGetByIDUserModified = DataRepository.KlijentNapomenaProvider.GetByIDUserModified(transactionManager, entity.ID);

				if (deep && entity.KlijentNapomenaCollectionGetByIDUserModified.Count > 0)
				{
					deepHandles.Add("KlijentNapomenaCollectionGetByIDUserModified",
						new KeyValuePair<Delegate, object>((DeepLoadHandle<KlijentNapomena>) DataRepository.KlijentNapomenaProvider.DeepLoad,
						new object[] { transactionManager, entity.KlijentNapomenaCollectionGetByIDUserModified, deep, deepLoadType, childTypes, innerList }
					));
				}
			}		
			#endregion 
			
			
			#region DokumentCollectionGetByIDUserIzdao
			//Relationship Type One : Many
			if (CanDeepLoad(entity, "List<Dokument>|DokumentCollectionGetByIDUserIzdao", deepLoadType, innerList)) 
			{
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'DokumentCollectionGetByIDUserIzdao' loaded. key " + entity.EntityTrackingKey);
				#endif 

				entity.DokumentCollectionGetByIDUserIzdao = DataRepository.DokumentProvider.GetByIDUserIzdao(transactionManager, entity.ID);

				if (deep && entity.DokumentCollectionGetByIDUserIzdao.Count > 0)
				{
					deepHandles.Add("DokumentCollectionGetByIDUserIzdao",
						new KeyValuePair<Delegate, object>((DeepLoadHandle<Dokument>) DataRepository.DokumentProvider.DeepLoad,
						new object[] { transactionManager, entity.DokumentCollectionGetByIDUserIzdao, deep, deepLoadType, childTypes, innerList }
					));
				}
			}		
			#endregion 
			
			
			#region KlijentNapomenaCollectionGetByIDUserCreated
			//Relationship Type One : Many
			if (CanDeepLoad(entity, "List<KlijentNapomena>|KlijentNapomenaCollectionGetByIDUserCreated", deepLoadType, innerList)) 
			{
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'KlijentNapomenaCollectionGetByIDUserCreated' loaded. key " + entity.EntityTrackingKey);
				#endif 

				entity.KlijentNapomenaCollectionGetByIDUserCreated = DataRepository.KlijentNapomenaProvider.GetByIDUserCreated(transactionManager, entity.ID);

				if (deep && entity.KlijentNapomenaCollectionGetByIDUserCreated.Count > 0)
				{
					deepHandles.Add("KlijentNapomenaCollectionGetByIDUserCreated",
						new KeyValuePair<Delegate, object>((DeepLoadHandle<KlijentNapomena>) DataRepository.KlijentNapomenaProvider.DeepLoad,
						new object[] { transactionManager, entity.KlijentNapomenaCollectionGetByIDUserCreated, deep, deepLoadType, childTypes, innerList }
					));
				}
			}		
			#endregion 
			
			
			#region KnjizenjeCollectionGetByIDUser
			//Relationship Type One : Many
			if (CanDeepLoad(entity, "List<Knjizenje>|KnjizenjeCollectionGetByIDUser", deepLoadType, innerList)) 
			{
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'KnjizenjeCollectionGetByIDUser' loaded. key " + entity.EntityTrackingKey);
				#endif 

				entity.KnjizenjeCollectionGetByIDUser = DataRepository.KnjizenjeProvider.GetByIDUser(transactionManager, entity.ID);

				if (deep && entity.KnjizenjeCollectionGetByIDUser.Count > 0)
				{
					deepHandles.Add("KnjizenjeCollectionGetByIDUser",
						new KeyValuePair<Delegate, object>((DeepLoadHandle<Knjizenje>) DataRepository.KnjizenjeProvider.DeepLoad,
						new object[] { transactionManager, entity.KnjizenjeCollectionGetByIDUser, deep, deepLoadType, childTypes, innerList }
					));
				}
			}		
			#endregion 
			
			
			#region KnjizenjeCollectionGetByIDUserCreated
			//Relationship Type One : Many
			if (CanDeepLoad(entity, "List<Knjizenje>|KnjizenjeCollectionGetByIDUserCreated", deepLoadType, innerList)) 
			{
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'KnjizenjeCollectionGetByIDUserCreated' loaded. key " + entity.EntityTrackingKey);
				#endif 

				entity.KnjizenjeCollectionGetByIDUserCreated = DataRepository.KnjizenjeProvider.GetByIDUserCreated(transactionManager, entity.ID);

				if (deep && entity.KnjizenjeCollectionGetByIDUserCreated.Count > 0)
				{
					deepHandles.Add("KnjizenjeCollectionGetByIDUserCreated",
						new KeyValuePair<Delegate, object>((DeepLoadHandle<Knjizenje>) DataRepository.KnjizenjeProvider.DeepLoad,
						new object[] { transactionManager, entity.KnjizenjeCollectionGetByIDUserCreated, deep, deepLoadType, childTypes, innerList }
					));
				}
			}		
			#endregion 
			
			
			#region DjelatnikInGrupaCollection
			//Relationship Type One : Many
			if (CanDeepLoad(entity, "List<DjelatnikInGrupa>|DjelatnikInGrupaCollection", deepLoadType, innerList)) 
			{
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'DjelatnikInGrupaCollection' loaded. key " + entity.EntityTrackingKey);
				#endif 

				entity.DjelatnikInGrupaCollection = DataRepository.DjelatnikInGrupaProvider.GetByIDDjelatnik(transactionManager, entity.ID);

				if (deep && entity.DjelatnikInGrupaCollection.Count > 0)
				{
					deepHandles.Add("DjelatnikInGrupaCollection",
						new KeyValuePair<Delegate, object>((DeepLoadHandle<DjelatnikInGrupa>) DataRepository.DjelatnikInGrupaProvider.DeepLoad,
						new object[] { transactionManager, entity.DjelatnikInGrupaCollection, deep, deepLoadType, childTypes, innerList }
					));
				}
			}		
			#endregion 
			
			
			//Fire all DeepLoad Items
			foreach(KeyValuePair<Delegate, object> pair in deepHandles.Values)
		    {
                pair.Key.DynamicInvoke((object[])pair.Value);
		    }
			deepHandles = null;
		}
		
		#endregion 
		
		#region DeepSave Methods

		/// <summary>
		/// Deep Save the entire object graph of the NetROS.Tiers.Entities.Djelatnik object with criteria based of the child 
		/// Type property array and DeepSaveType.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="entity">NetROS.Tiers.Entities.Djelatnik instance</param>
		/// <param name="deepSaveType">DeepSaveType Enumeration to Include/Exclude object property collections from Save.</param>
		/// <param name="childTypes">NetROS.Tiers.Entities.Djelatnik Property Collection Type Array To Include or Exclude from Save</param>
		/// <param name="innerList">A Hashtable of child types for easy access.</param>
		internal override bool DeepSave(TransactionManager transactionManager, NetROS.Tiers.Entities.Djelatnik entity, DeepSaveType deepSaveType, System.Type[] childTypes, DeepSession innerList)
		{	
			if (entity == null)
				return false;
							
			#region Composite Parent Properties
			//Save Source Composite Properties, however, don't call deep save on them.  
			//So they only get saved a single level deep.
			
			#region IDOrganizacijaSource
			if (CanDeepSave(entity, "Organizacija|IDOrganizacijaSource", deepSaveType, innerList) 
				&& entity.IDOrganizacijaSource != null)
			{
				DataRepository.OrganizacijaProvider.Save(transactionManager, entity.IDOrganizacijaSource);
				entity.IDOrganizacija = entity.IDOrganizacijaSource.ID;
			}
			#endregion 
			#endregion Composite Parent Properties

			// Save Root Entity through Provider
			if (!entity.IsDeleted)
				this.Save(transactionManager, entity);
			
			//used to hold DeepSave method delegates and fire after all the local children have been saved.
			Dictionary<Delegate, object> deepHandles = new Dictionary<Delegate, object>();

			#region GrupaDjelatnikCollection_From_DjelatnikInGrupa>
			if (CanDeepSave(entity.GrupaDjelatnikCollection_From_DjelatnikInGrupa, "List<GrupaDjelatnik>|GrupaDjelatnikCollection_From_DjelatnikInGrupa", deepSaveType, innerList))
			{
				if (entity.GrupaDjelatnikCollection_From_DjelatnikInGrupa.Count > 0 || entity.GrupaDjelatnikCollection_From_DjelatnikInGrupa.DeletedItems.Count > 0)
				{
					DataRepository.GrupaDjelatnikProvider.Save(transactionManager, entity.GrupaDjelatnikCollection_From_DjelatnikInGrupa); 
					deepHandles.Add(
						(DeepSaveHandle<GrupaDjelatnik>) DataRepository.GrupaDjelatnikProvider.DeepSave,
						new object[] { transactionManager, entity.GrupaDjelatnikCollection_From_DjelatnikInGrupa, deepSaveType, childTypes, innerList }
					);
				}
			}
			#endregion 
	
			#region List<DokumentStavka>
				if (CanDeepSave(entity.DokumentStavkaCollection, "List<DokumentStavka>|DokumentStavkaCollection", deepSaveType, innerList)) 
				{	
					// update each child parent id with the real parent id (mostly used on insert)
					foreach(DokumentStavka child in entity.DokumentStavkaCollection)
					{
						if(child.IDUserModifiedSource != null)
							child.IDUserModified = child.IDUserModifiedSource.ID;
						else
							child.IDUserModified = entity.ID;

					}

					if (entity.DokumentStavkaCollection.Count > 0 || entity.DokumentStavkaCollection.DeletedItems.Count > 0)
					{
						DataRepository.DokumentStavkaProvider.Save(transactionManager, entity.DokumentStavkaCollection);
						
						deepHandles.Add(
							(DeepSaveHandle< DokumentStavka >) DataRepository.DokumentStavkaProvider.DeepSave,
							new object[] { transactionManager, entity.DokumentStavkaCollection, deepSaveType, childTypes, innerList }
						);
					}
				} 
			#endregion 
				
	
			#region List<Knjizenje>
				if (CanDeepSave(entity.KnjizenjeCollectionGetByIDUserModified, "List<Knjizenje>|KnjizenjeCollection", deepSaveType, innerList)) 
				{	
					// update each child parent id with the real parent id (mostly used on insert)
					foreach(Knjizenje child in entity.KnjizenjeCollectionGetByIDUserModified)
					{
						if(child.IDUserModifiedSource != null)
							child.IDUserModified = child.IDUserModifiedSource.ID;
						else
							child.IDUserModified = entity.ID;

					}

					if (entity.KnjizenjeCollectionGetByIDUserModified.Count > 0 || entity.KnjizenjeCollectionGetByIDUserModified.DeletedItems.Count > 0)
					{
						DataRepository.KnjizenjeProvider.Save(transactionManager, entity.KnjizenjeCollectionGetByIDUserModified);
						
						deepHandles.Add(
							(DeepSaveHandle< Knjizenje >) DataRepository.KnjizenjeProvider.DeepSave,
							new object[] { transactionManager, entity.KnjizenjeCollectionGetByIDUserModified, deepSaveType, childTypes, innerList }
						);
					}
				} 
			#endregion 
				
	
			#region List<KnjizenjeStavka>
				if (CanDeepSave(entity.KnjizenjeStavkaCollectionGetByIDUserCreated, "List<KnjizenjeStavka>|KnjizenjeStavkaCollection", deepSaveType, innerList)) 
				{	
					// update each child parent id with the real parent id (mostly used on insert)
					foreach(KnjizenjeStavka child in entity.KnjizenjeStavkaCollectionGetByIDUserCreated)
					{
						if(child.IDUserCreatedSource != null)
							child.IDUserCreated = child.IDUserCreatedSource.ID;
						else
							child.IDUserCreated = entity.ID;

					}

					if (entity.KnjizenjeStavkaCollectionGetByIDUserCreated.Count > 0 || entity.KnjizenjeStavkaCollectionGetByIDUserCreated.DeletedItems.Count > 0)
					{
						DataRepository.KnjizenjeStavkaProvider.Save(transactionManager, entity.KnjizenjeStavkaCollectionGetByIDUserCreated);
						
						deepHandles.Add(
							(DeepSaveHandle< KnjizenjeStavka >) DataRepository.KnjizenjeStavkaProvider.DeepSave,
							new object[] { transactionManager, entity.KnjizenjeStavkaCollectionGetByIDUserCreated, deepSaveType, childTypes, innerList }
						);
					}
				} 
			#endregion 
				
	
			#region List<Dokument>
				if (CanDeepSave(entity.DokumentCollectionGetByIDUserPrimio, "List<Dokument>|DokumentCollection", deepSaveType, innerList)) 
				{	
					// update each child parent id with the real parent id (mostly used on insert)
					foreach(Dokument child in entity.DokumentCollectionGetByIDUserPrimio)
					{
						if(child.IDUserPrimioSource != null)
							child.IDUserPrimio = child.IDUserPrimioSource.ID;
						else
							child.IDUserPrimio = entity.ID;

					}

					if (entity.DokumentCollectionGetByIDUserPrimio.Count > 0 || entity.DokumentCollectionGetByIDUserPrimio.DeletedItems.Count > 0)
					{
						DataRepository.DokumentProvider.Save(transactionManager, entity.DokumentCollectionGetByIDUserPrimio);
						
						deepHandles.Add(
							(DeepSaveHandle< Dokument >) DataRepository.DokumentProvider.DeepSave,
							new object[] { transactionManager, entity.DokumentCollectionGetByIDUserPrimio, deepSaveType, childTypes, innerList }
						);
					}
				} 
			#endregion 
				
	
			#region List<ObracunKamata>
				if (CanDeepSave(entity.ObracunKamataCollection, "List<ObracunKamata>|ObracunKamataCollection", deepSaveType, innerList)) 
				{	
					// update each child parent id with the real parent id (mostly used on insert)
					foreach(ObracunKamata child in entity.ObracunKamataCollection)
					{
						if(child.IDUserModifiedSource != null)
							child.IDUserModified = child.IDUserModifiedSource.ID;
						else
							child.IDUserModified = entity.ID;

					}

					if (entity.ObracunKamataCollection.Count > 0 || entity.ObracunKamataCollection.DeletedItems.Count > 0)
					{
						DataRepository.ObracunKamataProvider.Save(transactionManager, entity.ObracunKamataCollection);
						
						deepHandles.Add(
							(DeepSaveHandle< ObracunKamata >) DataRepository.ObracunKamataProvider.DeepSave,
							new object[] { transactionManager, entity.ObracunKamataCollection, deepSaveType, childTypes, innerList }
						);
					}
				} 
			#endregion 
				
	
			#region List<KnjizenjeStavka>
				if (CanDeepSave(entity.KnjizenjeStavkaCollectionGetByIDUserModified, "List<KnjizenjeStavka>|KnjizenjeStavkaCollection", deepSaveType, innerList)) 
				{	
					// update each child parent id with the real parent id (mostly used on insert)
					foreach(KnjizenjeStavka child in entity.KnjizenjeStavkaCollectionGetByIDUserModified)
					{
						if(child.IDUserModifiedSource != null)
							child.IDUserModified = child.IDUserModifiedSource.ID;
						else
							child.IDUserModified = entity.ID;

					}

					if (entity.KnjizenjeStavkaCollectionGetByIDUserModified.Count > 0 || entity.KnjizenjeStavkaCollectionGetByIDUserModified.DeletedItems.Count > 0)
					{
						DataRepository.KnjizenjeStavkaProvider.Save(transactionManager, entity.KnjizenjeStavkaCollectionGetByIDUserModified);
						
						deepHandles.Add(
							(DeepSaveHandle< KnjizenjeStavka >) DataRepository.KnjizenjeStavkaProvider.DeepSave,
							new object[] { transactionManager, entity.KnjizenjeStavkaCollectionGetByIDUserModified, deepSaveType, childTypes, innerList }
						);
					}
				} 
			#endregion 
				
	
			#region List<KlijentNapomena>
				if (CanDeepSave(entity.KlijentNapomenaCollectionGetByIDUserModified, "List<KlijentNapomena>|KlijentNapomenaCollection", deepSaveType, innerList)) 
				{	
					// update each child parent id with the real parent id (mostly used on insert)
					foreach(KlijentNapomena child in entity.KlijentNapomenaCollectionGetByIDUserModified)
					{
						if(child.IDUserModifiedSource != null)
							child.IDUserModified = child.IDUserModifiedSource.ID;
						else
							child.IDUserModified = entity.ID;

					}

					if (entity.KlijentNapomenaCollectionGetByIDUserModified.Count > 0 || entity.KlijentNapomenaCollectionGetByIDUserModified.DeletedItems.Count > 0)
					{
						DataRepository.KlijentNapomenaProvider.Save(transactionManager, entity.KlijentNapomenaCollectionGetByIDUserModified);
						
						deepHandles.Add(
							(DeepSaveHandle< KlijentNapomena >) DataRepository.KlijentNapomenaProvider.DeepSave,
							new object[] { transactionManager, entity.KlijentNapomenaCollectionGetByIDUserModified, deepSaveType, childTypes, innerList }
						);
					}
				} 
			#endregion 
				
	
			#region List<Dokument>
				if (CanDeepSave(entity.DokumentCollectionGetByIDUserIzdao, "List<Dokument>|DokumentCollection", deepSaveType, innerList)) 
				{	
					// update each child parent id with the real parent id (mostly used on insert)
					foreach(Dokument child in entity.DokumentCollectionGetByIDUserIzdao)
					{
						if(child.IDUserIzdaoSource != null)
							child.IDUserIzdao = child.IDUserIzdaoSource.ID;
						else
							child.IDUserIzdao = entity.ID;

					}

					if (entity.DokumentCollectionGetByIDUserIzdao.Count > 0 || entity.DokumentCollectionGetByIDUserIzdao.DeletedItems.Count > 0)
					{
						DataRepository.DokumentProvider.Save(transactionManager, entity.DokumentCollectionGetByIDUserIzdao);
						
						deepHandles.Add(
							(DeepSaveHandle< Dokument >) DataRepository.DokumentProvider.DeepSave,
							new object[] { transactionManager, entity.DokumentCollectionGetByIDUserIzdao, deepSaveType, childTypes, innerList }
						);
					}
				} 
			#endregion 
				
	
			#region List<KlijentNapomena>
				if (CanDeepSave(entity.KlijentNapomenaCollectionGetByIDUserCreated, "List<KlijentNapomena>|KlijentNapomenaCollection", deepSaveType, innerList)) 
				{	
					// update each child parent id with the real parent id (mostly used on insert)
					foreach(KlijentNapomena child in entity.KlijentNapomenaCollectionGetByIDUserCreated)
					{
						if(child.IDUserCreatedSource != null)
							child.IDUserCreated = child.IDUserCreatedSource.ID;
						else
							child.IDUserCreated = entity.ID;

					}

					if (entity.KlijentNapomenaCollectionGetByIDUserCreated.Count > 0 || entity.KlijentNapomenaCollectionGetByIDUserCreated.DeletedItems.Count > 0)
					{
						DataRepository.KlijentNapomenaProvider.Save(transactionManager, entity.KlijentNapomenaCollectionGetByIDUserCreated);
						
						deepHandles.Add(
							(DeepSaveHandle< KlijentNapomena >) DataRepository.KlijentNapomenaProvider.DeepSave,
							new object[] { transactionManager, entity.KlijentNapomenaCollectionGetByIDUserCreated, deepSaveType, childTypes, innerList }
						);
					}
				} 
			#endregion 
				
	
			#region List<Knjizenje>
				if (CanDeepSave(entity.KnjizenjeCollectionGetByIDUser, "List<Knjizenje>|KnjizenjeCollection", deepSaveType, innerList)) 
				{	
					// update each child parent id with the real parent id (mostly used on insert)
					foreach(Knjizenje child in entity.KnjizenjeCollectionGetByIDUser)
					{
						if(child.IDUserSource != null)
							child.IDUser = child.IDUserSource.ID;
						else
							child.IDUser = entity.ID;

					}

					if (entity.KnjizenjeCollectionGetByIDUser.Count > 0 || entity.KnjizenjeCollectionGetByIDUser.DeletedItems.Count > 0)
					{
						DataRepository.KnjizenjeProvider.Save(transactionManager, entity.KnjizenjeCollectionGetByIDUser);
						
						deepHandles.Add(
							(DeepSaveHandle< Knjizenje >) DataRepository.KnjizenjeProvider.DeepSave,
							new object[] { transactionManager, entity.KnjizenjeCollectionGetByIDUser, deepSaveType, childTypes, innerList }
						);
					}
				} 
			#endregion 
				
	
			#region List<Knjizenje>
				if (CanDeepSave(entity.KnjizenjeCollectionGetByIDUserCreated, "List<Knjizenje>|KnjizenjeCollection", deepSaveType, innerList)) 
				{	
					// update each child parent id with the real parent id (mostly used on insert)
					foreach(Knjizenje child in entity.KnjizenjeCollectionGetByIDUserCreated)
					{
						if(child.IDUserCreatedSource != null)
							child.IDUserCreated = child.IDUserCreatedSource.ID;
						else
							child.IDUserCreated = entity.ID;

					}

					if (entity.KnjizenjeCollectionGetByIDUserCreated.Count > 0 || entity.KnjizenjeCollectionGetByIDUserCreated.DeletedItems.Count > 0)
					{
						DataRepository.KnjizenjeProvider.Save(transactionManager, entity.KnjizenjeCollectionGetByIDUserCreated);
						
						deepHandles.Add(
							(DeepSaveHandle< Knjizenje >) DataRepository.KnjizenjeProvider.DeepSave,
							new object[] { transactionManager, entity.KnjizenjeCollectionGetByIDUserCreated, deepSaveType, childTypes, innerList }
						);
					}
				} 
			#endregion 
				
	
			#region List<DjelatnikInGrupa>
				if (CanDeepSave(entity.DjelatnikInGrupaCollection, "List<DjelatnikInGrupa>|DjelatnikInGrupaCollection", deepSaveType, innerList)) 
				{	
					// update each child parent id with the real parent id (mostly used on insert)
					foreach(DjelatnikInGrupa child in entity.DjelatnikInGrupaCollection)
					{
						if(child.IDDjelatnikSource != null)
							child.IDDjelatnik = child.IDDjelatnikSource.ID;
						else
							child.IDDjelatnik = entity.ID;

						//Handle right table of GrupaDjelatnikCollection_From_DjelatnikInGrupa
						if(child.IDDjelatnikSource != null)
						{
								child.IDDjelatnik = child.IDDjelatnikSource.ID;

						}

						//Handle right table of GrupaDjelatnikCollection_From_DjelatnikInGrupa
						if(child.IDGrupaDjelatnikSource != null)
						{
								child.IDGrupaDjelatnik = child.IDGrupaDjelatnikSource.ID;

						}

					}

					if (entity.DjelatnikInGrupaCollection.Count > 0 || entity.DjelatnikInGrupaCollection.DeletedItems.Count > 0)
					{
						DataRepository.DjelatnikInGrupaProvider.Save(transactionManager, entity.DjelatnikInGrupaCollection);
						
						deepHandles.Add(
							(DeepSaveHandle< DjelatnikInGrupa >) DataRepository.DjelatnikInGrupaProvider.DeepSave,
							new object[] { transactionManager, entity.DjelatnikInGrupaCollection, deepSaveType, childTypes, innerList }
						);
					}
				} 
			#endregion 
				
			//Fire all DeepSave Items
			foreach(KeyValuePair<Delegate, object> pair in deepHandles)
		    {
                pair.Key.DynamicInvoke((object[])pair.Value);
		    }
			
			// Save Root Entity through Provider, if not already saved in delete mode
			if (entity.IsDeleted)
				this.Save(transactionManager, entity);
				

			deepHandles = null;
						
			return true;
		}
		#endregion
	} // end class
	
	#region DjelatnikChildEntityTypes
	
	///<summary>
	/// Enumeration used to expose the different child entity types 
	/// for child properties in <c>NetROS.Tiers.Entities.Djelatnik</c>
	///</summary>
	public enum DjelatnikChildEntityTypes
	{
		
		///<summary>
		/// Composite Property for <c>Organizacija</c> at IDOrganizacijaSource
		///</summary>
		[ChildEntityType(typeof(Organizacija))]
		Organizacija,
	
		///<summary>
		/// Collection of <c>Djelatnik</c> as OneToMany for DokumentStavkaCollection
		///</summary>
		[ChildEntityType(typeof(TList<DokumentStavka>))]
		DokumentStavkaCollection,

		///<summary>
		/// Collection of <c>Djelatnik</c> as OneToMany for KnjizenjeCollection
		///</summary>
		[ChildEntityType(typeof(TList<Knjizenje>))]
		KnjizenjeCollectionGetByIDUserModified,

		///<summary>
		/// Collection of <c>Djelatnik</c> as OneToMany for KnjizenjeStavkaCollection
		///</summary>
		[ChildEntityType(typeof(TList<KnjizenjeStavka>))]
		KnjizenjeStavkaCollectionGetByIDUserCreated,

		///<summary>
		/// Collection of <c>Djelatnik</c> as OneToMany for DokumentCollection
		///</summary>
		[ChildEntityType(typeof(TList<Dokument>))]
		DokumentCollectionGetByIDUserPrimio,

		///<summary>
		/// Collection of <c>Djelatnik</c> as ManyToMany for GrupaDjelatnikCollection_From_DjelatnikInGrupa
		///</summary>
		[ChildEntityType(typeof(TList<GrupaDjelatnik>))]
		GrupaDjelatnikCollection_From_DjelatnikInGrupa,

		///<summary>
		/// Collection of <c>Djelatnik</c> as OneToMany for ObracunKamataCollection
		///</summary>
		[ChildEntityType(typeof(TList<ObracunKamata>))]
		ObracunKamataCollection,

		///<summary>
		/// Collection of <c>Djelatnik</c> as OneToMany for KnjizenjeStavkaCollection
		///</summary>
		[ChildEntityType(typeof(TList<KnjizenjeStavka>))]
		KnjizenjeStavkaCollectionGetByIDUserModified,

		///<summary>
		/// Collection of <c>Djelatnik</c> as OneToMany for KlijentNapomenaCollection
		///</summary>
		[ChildEntityType(typeof(TList<KlijentNapomena>))]
		KlijentNapomenaCollectionGetByIDUserModified,

		///<summary>
		/// Collection of <c>Djelatnik</c> as OneToMany for DokumentCollection
		///</summary>
		[ChildEntityType(typeof(TList<Dokument>))]
		DokumentCollectionGetByIDUserIzdao,

		///<summary>
		/// Collection of <c>Djelatnik</c> as OneToMany for KlijentNapomenaCollection
		///</summary>
		[ChildEntityType(typeof(TList<KlijentNapomena>))]
		KlijentNapomenaCollectionGetByIDUserCreated,

		///<summary>
		/// Collection of <c>Djelatnik</c> as OneToMany for KnjizenjeCollection
		///</summary>
		[ChildEntityType(typeof(TList<Knjizenje>))]
		KnjizenjeCollectionGetByIDUser,

		///<summary>
		/// Collection of <c>Djelatnik</c> as OneToMany for KnjizenjeCollection
		///</summary>
		[ChildEntityType(typeof(TList<Knjizenje>))]
		KnjizenjeCollectionGetByIDUserCreated,

		///<summary>
		/// Collection of <c>Djelatnik</c> as OneToMany for DjelatnikInGrupaCollection
		///</summary>
		[ChildEntityType(typeof(TList<DjelatnikInGrupa>))]
		DjelatnikInGrupaCollection,
	}
	
	#endregion DjelatnikChildEntityTypes
	
	#region DjelatnikFilterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="SqlFilterBuilder&lt;DjelatnikColumn&gt;"/> class
	/// that is used exclusively with a <see cref="Djelatnik"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class DjelatnikFilterBuilder : SqlFilterBuilder<DjelatnikColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the DjelatnikFilterBuilder class.
		/// </summary>
		public DjelatnikFilterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the DjelatnikFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public DjelatnikFilterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the DjelatnikFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public DjelatnikFilterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion DjelatnikFilterBuilder
	
	#region DjelatnikParameterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="ParameterizedSqlFilterBuilder&lt;DjelatnikColumn&gt;"/> class
	/// that is used exclusively with a <see cref="Djelatnik"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class DjelatnikParameterBuilder : ParameterizedSqlFilterBuilder<DjelatnikColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the DjelatnikParameterBuilder class.
		/// </summary>
		public DjelatnikParameterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the DjelatnikParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public DjelatnikParameterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the DjelatnikParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public DjelatnikParameterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion DjelatnikParameterBuilder
} // end namespace
